package com.wlb.test.service.rabbitmq.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wlb.test.util.rabbitmq.ConnectionUtil;
import com.wlb.test.util.rabbitmq.QueueEnum;

/**
 * @Author:wanglibing
 * @Mail:wanglibing@jd.com
 * @Date:Created in 9:27 2018/1/30
 * @Description:
 */
public class Send {
    public static void main(String[] args) throws Exception{
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
//          声明队列
        channel.queueDeclare(QueueEnum.QUEUE_NAME_WORK.getName(),false,false,false,null);

        for (int i = 0; i < 100; i++) {
            // 消息内容
            String message = "" + i;
//            通过管道发送消息到指定的队列中
            channel.basicPublish("",QueueEnum.QUEUE_NAME_WORK.getName(),null,message.getBytes());
            System.out.println(" [x] Sent '" + message + "'");

//            Thread.sleep(i * 10);
        }
        channel.close();
        connection.close();
    }
}
